%%detection of edges will start , denoising completed%%
clc;
clear all;
A=imread('img/object/ant/image_0001.jpg')
low=input('enter the low range ');
high=input('enter the high range ');
[l,h,v,d]=dwt2(A,'haar');
p=abs(h)+abs(v)+abs(d);
subplot(1,2,1);
imshow(A);
title('lena image after denoising');
[m n]=size(p);
mi=min(min(p));
ma=max(max(p));
thr=(ma+mi)/2;
satisfy=0;
while(satisfy==0)
    c=0;
    for i=1:m
        for j=1:n
            if p(i,j)>=thr
                c=c+1;
            end
        end
    end
    ratio=c/(m*n);
    if(ratio>=low&&ratio<=high)
        satisfy=1;
    elseif(ratio>high)
        mi=thr;
        thr=(thr+ma)/2;
        
    elseif(ratio<low)
        ma=thr;
        thr=(thr+mi)/2;
    end
    thr
end

for i = 1:m
    for j=1:n
        if p(i,j)> = thr
            p(i,j) = 500;
        else
            p(i,j) = 0;
        end
    end
end
im=idwt2([],[],[],p,'haar');
subplot(1,2,2);
imshow(im);
title('Haar wavelet detected image')

